package com.pretty.test.controller.system.dict;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.system.dict.dto.*;
import com.pretty.test.controller.system.dict.vo.*;
import com.pretty.test.entity.PetsDict;
import com.pretty.test.service.IPetsDictService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 系统字典控制器
 * @author dujianyu
 * @since 2021-03-31
 */
@RestController
@AllArgsConstructor
@RequestMapping("/dict")
public class PetsDictController {

    private IPetsDictService iPetsDictService;

    /**
     *  父级字典分页
     */
    @GetMapping("/page")
    public R<IPage<PetsDictVO>> page(Page<PetsDictVO> page, PetsDictSearchDTO searchDTO){

        return R.ok(iPetsDictService.selectDictList(page,searchDTO));
    }

    /**
     *  子级字典分页
     */
    @GetMapping("/childrenPage")
    public R<IPage<ChildrenPetsDictVO>> childrenPage(Page<ChildrenPetsDictVO> page, ChildrenPetsDictSearchDTO searchDTO){

        return R.ok(iPetsDictService.selectChildrenDictList(page,searchDTO));
    }

    /**
     *  新建修改字典
     */
    @PostMapping("/submit")
    public R<Boolean> submit(@RequestBody  PetsDict petsDict){
        return R.ok(iPetsDictService.submit(petsDict));
    }

    /**
     *  修改开启状态
     */
    @PostMapping("/changeIsRun")
    public R<Boolean> changeIsRun(@RequestBody PetsDict petsDict){
        return R.ok(iPetsDictService.changeIsRun(petsDict));
    }

    /**
     *  逻辑删除
     */
    @PostMapping("/delete")
    public R<Boolean> delete( String id){
        return R.ok(iPetsDictService.delete(id));
    }

    /**
     *  根据code获取字典
     */
    @GetMapping("/dictList")
    public R<List<DictKeyValueVO>> dictList(String code){
        return R.ok(iPetsDictService.dictList(code));
    }

}
